//
//  SHRecommendViewController.m
//  UI_CarHome
//
//  Created by dllo on 15/10/21.
//  Copyright (c) 2015年 沈浩. All rights reserved.
//

#import "SHRecommendViewController.h"
#import "SHHandle.h"
#import "SHModel.h"
#import "SHNewslistCell.h"
#import "SHThreeImageCell.h"
#import "SHDetailViewController.h"

#import "SHSearchViewController.h"

#import "SHHeaderCollectionCell.h"



@interface SHRecommendViewController ()<UITableViewDataSource, UITableViewDelegate, UIScrollViewDelegate, UICollectionViewDataSource, UICollectionViewDelegate>


@property(nonatomic, retain)UIScrollView *scrollView;
@property(nonatomic, retain)UIPageControl *pageControl;
@property(nonatomic, retain) NSString *nextStr;
@property(nonatomic, assign)NSInteger page;
@property(nonatomic, retain)MBProgressHUD *hud;
@property(nonatomic, retain)NSString *WebsiteStr;
@property(nonatomic, retain)UIScrollView *headScrollView;
@property(nonatomic, retain)NSArray *headScrollViewArr;


@property(nonatomic, assign)NSInteger nt;
@property(nonatomic, assign)NSInteger number;
@property(nonatomic, retain)NSString *url;
@property(nonatomic, retain)NSTimer *timer;

// 主界面scrollView
@property(nonatomic, retain)UIScrollView *bottomScrollView;
// tableView
@property(nonatomic, retain)UITableView *latestTableView;
@property(nonatomic, retain)UITableView *fastTableView;
@property(nonatomic, retain)UITableView *newsTableView;
@property(nonatomic, retain)UITableView *guideTableView;
@property(nonatomic, retain)UITableView *travelTableView;
// 数据数组
@property(nonatomic, retain)NSMutableArray *lastestArray;
@property(nonatomic, retain)NSMutableArray *lastetScrollViewArr;
@property(nonatomic, retain)NSMutableArray *fastArr;
@property(nonatomic, retain)NSMutableArray *newsArr;
@property(nonatomic, retain)NSMutableArray *guideArr;
@property(nonatomic, retain)NSMutableArray *travelArr;
@property(nonatomic, copy)NSString *focusimgUrl;
@property(nonatomic, retain)NSDictionary *urlDic;
@property(nonatomic, retain)UICollectionView *headCollectionView;
@property(nonatomic, assign)NSInteger selectIndex;
@end

@implementation SHRecommendViewController

- (void)dealloc
{
    [_headCollectionView release];
    [_focusimgUrl release];
    [_scrollView release];
    [_pageControl release];
    [_nextStr release];
    [_hud release];
    [_WebsiteStr release];
    [_headScrollView release];
    [_headScrollViewArr release];
    [_bottomScrollView release];
    [_latestTableView release];
    [_fastTableView release];
    [_newsTableView release];
    [_guideTableView release];
    [_travelTableView release];
    [_lastestArray release];
    [_lastetScrollViewArr release];
    [_fastArr release];
    [_newsArr release];
    [_guideArr release];
    [_travelArr release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self createHeaderCollectionView];
    [self createBottomScrollView];
    [self createLatestTableView];
    [self createFastTableView];
    [self createNewsTableView];
    [self createGuideTableView];
    [self createTravelTableView];
    self.view.backgroundColor = BACKGROUNDCOLOR;
    self.latestTableView.backgroundColor = BACKGROUNDCOLOR;
    self.fastTableView.backgroundColor = BACKGROUNDCOLOR;
    self.newsTableView.backgroundColor = BACKGROUNDCOLOR;
    self.guideTableView.backgroundColor = BACKGROUNDCOLOR;
    self.travelTableView.backgroundColor = BACKGROUNDCOLOR;
    
    self.latestTableView.separatorStyle = SEPARATORSTYLE;
    self.fastTableView.separatorStyle = SEPARATORSTYLE;
    self.newsTableView.separatorStyle = SEPARATORSTYLE;
    self.guideTableView.separatorStyle = SEPARATORSTYLE;
    self.travelTableView.separatorStyle = SEPARATORSTYLE;
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(isNight:) name:@"isNight" object:nil];
    
    // navigationBar不透明
    self.navigationController.navigationBar.translucent = NO;

    [self createHud];
    [self createLatestData];
    [self createHeaderAndFooter];

    // 添加导航栏右边的搜索的按钮
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"sousuo.png"] style:UIBarButtonItemStylePlain target:self action:@selector(searchAction:)];
    
}
// 夜间
- (void)isNight:(NSNotification *)nsnotification {
    
    [self.latestTableView reloadData];
    [self.fastTableView reloadData];
    [self.newsTableView reloadData];
    [self.guideTableView reloadData];
    [self.travelTableView reloadData];
    self.view.backgroundColor = BACKGROUNDCOLOR;
    self.latestTableView.backgroundColor = BACKGROUNDCOLOR;
    self.fastTableView.backgroundColor = BACKGROUNDCOLOR;
    self.newsTableView.backgroundColor = BACKGROUNDCOLOR;
    self.guideTableView.backgroundColor = BACKGROUNDCOLOR;
    self.travelTableView.backgroundColor = BACKGROUNDCOLOR;
    
    self.latestTableView.separatorStyle = SEPARATORSTYLE;
    self.fastTableView.separatorStyle = SEPARATORSTYLE;
    self.newsTableView.separatorStyle = SEPARATORSTYLE;
    self.guideTableView.separatorStyle = SEPARATORSTYLE;
    self.travelTableView.separatorStyle = SEPARATORSTYLE;
}

#pragma mark --跳转到search界面
- (void)searchAction:(UIBarButtonItem *)button {
    SHSearchViewController *search = [[SHSearchViewController alloc] init];
    // 隐藏backButton
//    search.navigationItem.hidesBackButton = YES;
    [self.navigationController pushViewController:search animated:YES];
    [search release];
}

#pragma mark --createHeaderAndFooter
- (void)createHeaderAndFooter
{
    // 下拉刷新
    self.latestTableView.header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(header)];
    self.fastTableView.header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(header)];
    self.newsTableView.header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(header)];
    self.guideTableView.header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(header)];
    self.travelTableView.header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(header)];
    // 上拉加载
    self.latestTableView.footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(footer)];
    self.fastTableView.footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(footer)];
    self.newsTableView.footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(footer)];
    self.guideTableView.footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(footer)];
    self.travelTableView.footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(footer)];
}

#pragma mark tableViewScrollView
- (void)createBottomScrollView
{
    self.bottomScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
    [self.view addSubview:self.bottomScrollView];
    [_bottomScrollView release];
    self.bottomScrollView.pagingEnabled = YES;
    self.bottomScrollView.showsHorizontalScrollIndicator = YES;
    self.bottomScrollView.contentSize = CGSizeMake(WIDTH * 5, 0);
    self.bottomScrollView.delegate = self;
    self.bottomScrollView.bounces = NO;
    
    
}

#pragma mark 最新界面tableView
- (void)createLatestTableView {
    self.latestTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT) style:UITableViewStylePlain];
    [self.bottomScrollView addSubview:self.latestTableView];
    [_latestTableView release];
    self.latestTableView.dataSource = self;
    self.latestTableView.delegate = self;
}
#pragma mark 快报页tableView
- (void)createFastTableView
{
    self.fastTableView = [[UITableView alloc] initWithFrame:CGRectMake(WIDTH, 0, WIDTH, HEIGHT - 64 * WID) style:UITableViewStylePlain];
    [self.bottomScrollView addSubview:self.fastTableView];
    [_fastTableView release];
    self.fastTableView.dataSource = self;
    self.fastTableView.delegate = self;
}
#pragma mark 新闻页tableView
- (void)createNewsTableView
{
    self.newsTableView = [[UITableView alloc] initWithFrame:CGRectMake(WIDTH * 2, 0, WIDTH, HEIGHT) style:UITableViewStylePlain];
    [self.bottomScrollView addSubview:self.newsTableView];
    [_newsTableView release];
    self.newsTableView.dataSource = self;
    self.newsTableView.delegate = self;
}
#pragma mark 导购页tableView
- (void)createGuideTableView {
    self.guideTableView = [[UITableView alloc] initWithFrame:CGRectMake(WIDTH * 3, 0, WIDTH, HEIGHT) style:UITableViewStylePlain];
    [self.bottomScrollView addSubview:self.guideTableView];
    [_guideTableView release];
    self.guideTableView.delegate = self;
    self.guideTableView.dataSource = self;
}
#pragma mark 游记页tableView
- (void)createTravelTableView {
    self.travelTableView = [[UITableView alloc] initWithFrame:CGRectMake(WIDTH * 4, 0, WIDTH, HEIGHT) style:UITableViewStylePlain];
    [self.bottomScrollView addSubview:self.travelTableView];
    [_travelTableView release];
    self.travelTableView.dataSource = self;
    self.travelTableView.delegate = self;
    
}

#pragma mark 最新页数据
- (void)createLatestData
{
      [SHNetWorkingTool getNetWorking:@"http://app.api.autohome.com.cn/autov5.0.0/news/newslist-pm2-c0-nt0-p1-s30-l0.json" block:^(id result) {
                 NSDictionary *dic = result;
        self.lastestArray = [NSMutableArray array];
        self.lastestArray = [SHModel baseModelByArr:dic[@"result"][@"newslist"]];
        // 轮播图
        self.lastetScrollViewArr = [NSMutableArray array];
        self.lastetScrollViewArr = [SHModel baseModelByArr:dic[@"result"][@"focusimg"]];
        [self createScrollView];

          
        [self.latestTableView reloadData];
        
    }];
    [self createFastData];
}
#pragma mark 快报页数据
- (void)createFastData {
    [SHNetWorkingTool getNetWorking:@"http://app.api.autohome.com.cn/autov5.0.0/news/fastnewslist-pm1-b0-l0-s20-lastid0.json" block:^(id result) {
        NSDictionary *dic = result;
        self.fastArr = [NSMutableArray array];
        self.fastArr = [SHModel baseModelByArr:dic[@"result"][@"list"]];
        [self.fastTableView reloadData];
    
    }];
    [self.fastTableView.header endRefreshing];
    [self createNewsData];
}
#pragma mark 新闻页数据
- (void)createNewsData {
    [SHNetWorkingTool getNetWorking:@"http://app.api.autohome.com.cn/autov5.0.0/news/newslist-pm1-c0-nt1-p1-s30-l0.json" block:^(id result) {
        NSDictionary *dic = result;
        self.newsArr = [NSMutableArray array];
        self.newsArr = [SHModel baseModelByArr:dic[@"result"][@"newslist"]];
        [self.newsTableView reloadData];
    }];
    [self.newsTableView.header endRefreshing];
    [self createGuideData];
}
#pragma mark 导购
- (void)createGuideData {
    [SHNetWorkingTool getNetWorking:@"http://app.api.autohome.com.cn/autov5.0.0/news/newslist-pm1-c0-nt60-p1-s30-l0.json" block:^(id result) {
        NSDictionary *dic = result;
        self.guideArr = [NSMutableArray array];
        self.guideArr = [SHModel baseModelByArr:dic[@"result"][@"newslist"]];
        [self.guideTableView reloadData];
    }];
    [self.guideTableView.header endRefreshing];
    [self createTravelData];
}
#pragma mark 游记
- (void)createTravelData {
    [SHNetWorkingTool getNetWorking:@"http://app.api.autohome.com.cn/autov5.0.0/news/newslist-pm1-c0-nt100-p1-s30-l0.json" block:^(id result) {
        NSDictionary *dic = result;
        self.travelArr = [NSMutableArray array];
        self.travelArr = [SHModel baseModelByArr:dic[@"result"][@"newslist"]];
        [self.travelTableView reloadData];
    }];
    [self.travelTableView.header endRefreshing];
}



#pragma mark 导航栏的button的点击方法实现与tableView的关联实现

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    if (scrollView == self.scrollView) {
        // 轮播图
        if (self.scrollView.contentOffset.x == WIDTH * (self.lastetScrollViewArr.count + 1)) {
            self.scrollView.contentOffset = CGPointMake(WIDTH, 0);
        } else if (self.scrollView.contentOffset.x == 0) {
            self.scrollView.contentOffset = CGPointMake(self.lastetScrollViewArr.count * WIDTH, 0);
        }
        self.pageControl.currentPage = self.scrollView.contentOffset.x / WIDTH - 1;
    } else if (scrollView == self.bottomScrollView) {
        self.selectIndex = self.bottomScrollView.contentOffset.x / WIDTH;
        [self.headCollectionView reloadData];
    }
   
}

- (void)createHeaderCollectionView {
    UICollectionViewFlowLayout *headFlowLayout = [[UICollectionViewFlowLayout alloc] init];
    headFlowLayout.itemSize = CGSizeMake(50 * WID, 35 * HEI);
    headFlowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    self.headCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 35 * WID) collectionViewLayout:headFlowLayout];
    self.navigationItem.titleView = self.headCollectionView;
    self.headCollectionView.dataSource = self;
    self.headCollectionView.delegate = self;
    self.headCollectionView.bounces = NO;
    [self.headCollectionView registerClass:[SHHeaderCollectionCell class] forCellWithReuseIdentifier:@"headerCollection"];
    self.headCollectionView.backgroundColor = [UIColor whiteColor];
    [_headCollectionView release];
    
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    SHHeaderCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"headerCollection" forIndexPath:indexPath];
    for (NSInteger i = 0; i < 5; i++) {
        cell.nowView.hidden = YES;
        cell.label.textColor = [UIColor blackColor];
    }
    if (indexPath.row == self.selectIndex) {
        cell.nowView.hidden = NO;
        cell.label.textColor = [UIColor redColor];
    }
    if (indexPath.row == 0) {
        cell.label.text = @"最新";
    } else if (indexPath.row == 1) {
        cell.label.text = @"快报";
    } else if (indexPath.row == 2) {
        cell.label.text = @"新闻";
    } else if (indexPath.row == 3) {
        cell.label.text = @"导购";
    } else if (indexPath.row == 4) {
        cell.label.text = @"游记";
    }
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    self.selectIndex = indexPath.row;
    self.bottomScrollView.contentOffset = CGPointMake(WIDTH * self.selectIndex, 0);
    [self.headCollectionView reloadData];
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 5;
}



- (void)createScrollView
{
    if (self.timer) {
       [self.timer invalidate];
    }

        // scrollView
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 200 * HEI)];
    
        self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 200 * HEI)];
        self.latestTableView.tableHeaderView = view;
        [view addSubview:self.scrollView];
        [_scrollView release];
        self.scrollView.delegate = self;
        self.scrollView.pagingEnabled = YES;
        self.scrollView.contentSize = CGSizeMake(WIDTH * (2 + self.lastetScrollViewArr.count), 200);
        self.scrollView.contentOffset = CGPointMake(WIDTH, 0);
        self.timer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(changeImage) userInfo:nil repeats:YES];
    
        // scrollView图片
        UIImageView *firstImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 200 * HEI)];
    [firstImageView sd_setImageWithURL:[NSURL URLWithString:[self.lastetScrollViewArr[self.lastetScrollViewArr.count - 1] imgurl]] placeholderImage:PLACEPICTURE];
        [self.scrollView addSubview:firstImageView];
        [firstImageView release];
    

    
        for(NSInteger i = 1; i <= self.lastetScrollViewArr.count; i++){
            UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH * i, 0, WIDTH, 200 * HEI)];
            [imageView sd_setImageWithURL:[NSURL URLWithString:[self.lastetScrollViewArr[i - 1] imgurl]] placeholderImage:PLACEPICTURE];
            [self.scrollView addSubview:imageView];
            [imageView release];
            
        }
        
        UIImageView *lastImageView = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH * (self.lastetScrollViewArr.count + 1), 0, WIDTH, 200 * HEI)];
        [lastImageView sd_setImageWithURL:[NSURL URLWithString:[self.lastetScrollViewArr[0] imgurl]] placeholderImage:PLACEPICTURE];
        [self.scrollView addSubview:lastImageView];
        [lastImageView release];
    
    
        
        // page
        self.pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(100 * WID, 160 * HEI, 160 * WID, 30 * HEI)];
        [view addSubview:self.pageControl];
        self.pageControl.numberOfPages = self.lastetScrollViewArr.count;
        self.pageControl.currentPageIndicatorTintColor = [UIColor grayColor];
        self.pageControl.pageIndicatorTintColor = [UIColor blackColor];
        [self.pageControl addTarget:self action:@selector(pageAction:) forControlEvents:UIControlEventValueChanged];
    
   
    
    
}

- (void)createHud
{
    self.hud = [[MBProgressHUD alloc] initWithView:self.view];
    [self.bottomScrollView addSubview:self.hud];
    // 如果设置此属性则当前的view置于后台
    self.hud.dimBackground = YES;
    self.hud.labelText = @"正在加载...";
    
    [self.hud showAnimated:YES whileExecutingBlock:^{
        //
        sleep(3);
    } completionBlock:^{
        // 操作执行完后取消对话框
        [self.hud removeFromSuperview];
        [self.hud release];
        self.hud = nil;
    }];
}



- (void)pageAction:(UIPageControl *)page
{
    [self.scrollView setContentOffset:CGPointMake(self.pageControl.currentPage * WIDTH, 0)];
}

- (void)changeImage
{
    [self.scrollView setContentOffset:CGPointMake(self.scrollView.contentOffset.x + WIDTH, 0) animated:YES];
    if (self.scrollView.contentOffset.x == WIDTH * self.lastetScrollViewArr.count) {
        self.scrollView.contentOffset = CGPointMake(0, 0);
    }
    self.pageControl.currentPage = self.scrollView.contentOffset.x / WIDTH;
    
    
}



// 下拉刷新
- (void)header
{
    [self.timer invalidate];
    if (self.latestTableView) {
        [self createLatestData];
        [self.latestTableView.header endRefreshing];
    } else if (self.fastTableView) {
        [self createFastData];
        
    } else if (self.newsTableView) {
        [self createNewsData];
        
    } else if (self.guideTableView) {
        [self createGuideData];
        
    } else {
        [self createTravelData];
        
    }
    
}
// 上拉加载
- (void)footer
{
    if (self.latestTableView) {
        self.page = 1;
        self.page++;
        for (SHModel *model in self.lastestArray) {
                self.nextStr = model.lasttime;
            }
        // 最新
        self.url = [NSString stringWithFormat:@"http://app.api.autohome.com.cn/autov5.0.0/news/newslist-pm1-c0-nt0-p%ld-s30-l%@.json", self.page, self.nextStr];
    } else if (self.fastTableView) {
        for (SHModel *model in self.fastArr) {
            self.nextStr = model.lasttime;
        }
        // 快报
        self.url = [NSString stringWithFormat:@"http://app.api.autohome.com.cn/autov5.0.0/news/newslist-pm1-c0-nt1-p1-s30-l%@.json", self.nextStr];
    }  else if (self.newsTableView) {
        for (SHModel *model in self.newsArr) {
            self.nextStr = model.lasttime;
        }
        // 新闻
        self.url = [NSString stringWithFormat:@"http://app.api.autohome.com.cn/autov5.0.0/news/newslist-pm1-c0-nt1-p1-s30-l%@.json", self.nextStr];
    } else if (self.guideTableView) {
        for (SHModel *model in self.guideArr) {
            self.nextStr = model.lasttime;
        }
        // 导购
        self.url = [NSString stringWithFormat:@"http://app.api.autohome.com.cn/autov5.0.0/news/newslist-pm1-c0-nt60-p1-s30-l%@.json" , self.nextStr];
    } else {
        for (SHModel *model in self.travelArr) {
            self.nextStr = model.lasttime;
        }
        // 游记
        self.url = [NSString stringWithFormat:@"http://app.api.autohome.com.cn/autov5.0.0/news/newslist-pm1-c0-nt100-p1-s30-l%@.json", self.nextStr];
    }
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:self.url parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *dic = responseObject;
        for (NSMutableDictionary *temp in dic[@"result"][@"newslist"]) {
            SHModel *model = [[SHModel alloc] init];
            [model setValuesForKeysWithDictionary:temp];
            [self.lastestArray addObject:model];
            [self.fastArr addObject:model];
            [self.newsArr addObject:model];
            [self.guideArr addObject:model];
            [self.travelArr addObject:model];
            [model release];
        }
        [self.latestTableView reloadData];
        [self.latestTableView.footer endRefreshing];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
    
}





- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == self.latestTableView) {
        SHModel *model = self.lastestArray[indexPath.row];
        if ([model.mediatype isEqualToNumber:@10]) {
            static NSString *reuse = @"threeReuse";
            SHThreeImageCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
            if (!cell) {
                cell = [[[SHThreeImageCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse] autorelease];
            }
            cell.titleLabel.text = model.title;
            cell.titleLabel.textColor = TEXTCOLOR;
            NSArray *indexdetailArr = [model.indexdetail componentsSeparatedByString:@"㊣"];
            [cell.leftImageView sd_setImageWithURL:[NSURL URLWithString:indexdetailArr[0]] placeholderImage:PLACEPICTURE];
            [cell.centerImageView sd_setImageWithURL:[NSURL URLWithString:indexdetailArr[1]] placeholderImage:PLACEPICTURE];
            [cell.rightImageView sd_setImageWithURL:[NSURL URLWithString:indexdetailArr[2]] placeholderImage:PLACEPICTURE];
            cell.timeLabel.text = model.time;
            cell.timeLabel.textColor = TEXTCOLOR;
            cell.replycountLabel.text = [NSString stringWithFormat:@"%@", model.replycount];
            cell.replycountLabel.textColor = TEXTCOLOR;
            cell.tushuoLabel.text = @"图说";
            return cell;
        } else if ([model.mediatype isEqualToNumber:@6]) {
            static NSString *reuse = @"threeReuse";
            SHThreeImageCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
            if (!cell) {
                cell = [[[SHThreeImageCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse] autorelease];
            }
            cell.titleLabel.text = model.title;
            cell.titleLabel.textColor = TEXTCOLOR;
            NSArray *indexdetailArray = [model.indexdetail componentsSeparatedByString:@","];
            NSArray *firstArray = [indexdetailArray[0] componentsSeparatedByString:@"㊣"];
            [cell.leftImageView sd_setImageWithURL:[NSURL URLWithString:firstArray[2]] placeholderImage:PLACEPICTURE];
            [cell.centerImageView sd_setImageWithURL:[NSURL URLWithString:indexdetailArray[1]] placeholderImage:PLACEPICTURE];
            [cell.rightImageView sd_setImageWithURL:[NSURL URLWithString:indexdetailArray[2]] placeholderImage:PLACEPICTURE];
            cell.timeLabel.text = model.time;
            cell.timeLabel.textColor = TEXTCOLOR;
            cell.timeLabel.font = [UIFont systemFontOfSize:12];
            return cell;
        } else {
            static NSString *reuse = @"oneReuse";
            SHNewslistCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
            if (!cell) {
                cell = [[[SHNewslistCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse] autorelease];
            }
            [cell.leftImageView sd_setImageWithURL:[NSURL URLWithString:model.smallpic] placeholderImage:PLACEPICTURE];
            cell.titleLabel.text = model.title;
            cell.titleLabel.textColor = TEXTCOLOR;
            [cell.titleLabel sizeToFit];
            cell.titleLabel.numberOfLines = 2;
            cell.timeLabel.text = model.time;
            cell.timeLabel.font = [UIFont systemFontOfSize:10];
            cell.timeLabel.textColor = TEXTCOLOR;
            cell.replycountLabel.font = [UIFont systemFontOfSize:10];
            cell.replycountLabel.textAlignment = YES;
            cell.replycountLabel.textColor = TEXTCOLOR;
            
            {
                if ([model.mediatype isEqualToNumber:@3]) {
                    cell.replycountLabel.text = [NSString stringWithFormat:@"%@%@", model.replycount, @"播放"];
                    cell.replycountLabel.textAlignment = NSTextAlignmentRight;
                } else if([model.mediatype isEqualToNumber:@7]){
                    cell.replycountLabel.text = @"播报中";
                } else if([model.mediatype isEqualToNumber:@5]){
                    cell.replycountLabel.text = [NSString stringWithFormat:@"%@%@", model.replycount, @"回帖"];
                    cell.replycountLabel.textAlignment = NSTextAlignmentRight;
                } else if([model.mediatype isEqualToNumber:@2]) {
                    cell.shuoKeLabel.text = @"说客";
                    cell.shuoKeLabel.textAlignment = YES;
    
                    cell.shuoKeLabel.textColor = [UIColor whiteColor];
                    cell.shuoKeLabel.font = [UIFont systemFontOfSize:10];
                    cell.replycountLabel.text = [NSString stringWithFormat:@"%@%@", model.replycount, @"评论"];
                    cell.replycountLabel.textAlignment = NSTextAlignmentRight;
                } else {
                    cell.replycountLabel.text = [NSString stringWithFormat:@"%@%@", model.replycount, @"评论"];
                    cell.replycountLabel.textAlignment = NSTextAlignmentRight;
                    
                }
            }
            return cell;
        }
        
    } else if (tableView == self.fastTableView) {
        SHModel *model = self.fastArr[indexPath.row];
        static NSString *reuse = @"fastReuse";
        SHBigPictureCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
        if (!cell) {
            cell = [[[SHBigPictureCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse] autorelease];
        }
        cell.typenameLabel.text = model.typename;
        cell.typenameLabel.textColor = [UIColor blueColor];
        cell.typenameLabel.font = [UIFont systemFontOfSize:12];
        [cell.bgimageView sd_setImageWithURL:[NSURL URLWithString:model.bgimage] placeholderImage:PLACEPICTURE];
        cell.titleLabel.text = model.title;
        cell.titleLabel.textColor = TEXTCOLOR;
        cell.titleLabel.numberOfLines = 2;
        
        cell.timeLabel.text = model.createtime;
        cell.timeLabel.textColor = [UIColor grayColor];
        cell.timeLabel.font = [UIFont systemFontOfSize:10];
        cell.timeLabel.textColor = TEXTCOLOR;
        cell.audienceLabel.text = [NSString stringWithFormat:@"%@%@", model.reviewcount, @"位观众"];
        cell.audienceLabel.font = [UIFont systemFontOfSize:12];
        cell.audienceLabel.textAlignment = NSTextAlignmentRight;
        cell.audienceLabel.textColor = TEXTCOLOR;
        return cell;
    } else if (tableView == self.newsTableView) {
        static NSString *reuse = @"newsReuse";
        SHNewslistCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
        if (!cell) {
            cell = [[[SHNewslistCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse] autorelease];
        }
        SHModel *model = self.newsArr[indexPath.row];
        cell.timeLabel.text = model.time;
        cell.timeLabel.textColor = TEXTCOLOR;
        cell.titleLabel.text = model.title;
        cell.titleLabel.textColor = TEXTCOLOR;
        cell.titleLabel.numberOfLines = 2;
        
        cell.replycountLabel.text = [NSString stringWithFormat:@"%@", model.replycount];
        cell.replycountLabel.textColor = TEXTCOLOR;
        [cell.leftImageView sd_setImageWithURL:[NSURL URLWithString:model.smallpic] placeholderImage:PLACEPICTURE];
        return cell;
    } else if (tableView == self.guideTableView) {
        static NSString *reuse = @"guideReuse";
        SHNewslistCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
        if (!cell) {
            cell = [[[SHNewslistCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse] autorelease];
        }
        SHModel *model = self.guideArr[indexPath.row];
        cell.timeLabel.text = model.time;
        cell.timeLabel.textColor = TEXTCOLOR;
        cell.titleLabel.text = model.title;
        cell.titleLabel.textColor = TEXTCOLOR;
        cell.titleLabel.numberOfLines = 2;
        
        cell.replycountLabel.text = [NSString stringWithFormat:@"%@", model.replycount];
        [cell.leftImageView sd_setImageWithURL:[NSURL URLWithString:model.smallpic] placeholderImage:PLACEPICTURE];

        return cell;
    } else {
        static NSString *reuse = @"testReuse";
        SHNewslistCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
        if (!cell) {
            cell = [[[SHNewslistCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse] autorelease];
        }
        SHModel *model = self.travelArr[indexPath.row];
        cell.timeLabel.text = model.time;
        cell.timeLabel.textColor = TEXTCOLOR;
        cell.titleLabel.text = model.title;
        cell.titleLabel.numberOfLines = 2;
        
        cell.titleLabel.textColor = TEXTCOLOR;
        cell.replycountLabel.text = [NSString stringWithFormat:@"%@", model.replycount];
        [cell.leftImageView sd_setImageWithURL:[NSURL URLWithString:model.smallpic] placeholderImage:PLACEPICTURE];
        

        return cell;
    }


    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == self.latestTableView) {
        SHModel *model = self.lastestArray[indexPath.row];
        if ([model.indexdetail isEqualToString:@""]) {
            return 120;
        } else {
            return 140;
        }
    } else if (tableView == self.fastTableView) {
        return 200;
    }else  {
        return 120;
    }

    
  
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    if (tableView == self.latestTableView) {
        return self.lastestArray.count;
    } else if (tableView == self.fastTableView) {
        return self.fastArr.count;
    } else if (tableView == self.newsTableView) {
        return self.newsArr.count;
    } else if (tableView == self.guideTableView) {
        return self.guideArr.count;
    } else  {
        return self.travelArr.count;
    }

}
#pragma mark tableView点击方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    SHModel *model = self.lastestArray[indexPath.row];
    NSString *mediatypeStr = [NSString stringWithFormat:@"%@", model.mediatype];
    NSString *idStr = [NSString stringWithFormat:@"%@", model.myId];
    NSString *str1 = @"http://comm.app.api.autohome.com.cn/static/sharejump.html?p=1&pm=1&go=1&cont=";
    NSString *str2 = @"&ourl=http://cont.app.autohome.com.cn/autov5.0.0/content/";
    NSString *str3 = @".html";
    // 说客
    if ([mediatypeStr isEqualToString:@"2"]) {
        NSString *p = @"news/shuokesharedcontent-n";
        self.WebsiteStr = [NSString stringWithFormat:@"%@%ld%@%@%@%@", str1, indexPath.row, str2, p, idStr, str3];
        NSLog(@"%@", self.WebsiteStr);
    } else if ([mediatypeStr isEqualToString:@"10"]) {
        
        NSString *p = @"News/newssharedcontent-n";
        self.WebsiteStr = [NSString stringWithFormat:@"%@%ld%@%@%@%@", str1, indexPath.row, str2, p, idStr, str3];
        NSLog(@"%@", self.WebsiteStr);
    } else if ([mediatypeStr isEqualToString:@"6"]) {
        NSString *p = @"&ourl=http://app.api.autohome.com.cn/autov5.0.0/cars/dutusharedcontent-pm1-ss896-sp23900-t1-imgid";
        self.WebsiteStr = [NSString stringWithFormat:@"%@%ld%@%@%@", str1, indexPath.row, p, idStr, str3];
        NSLog(@"%@", self.WebsiteStr);
    } else if ([mediatypeStr isEqualToString:@"1"]) {
        NSString *p = @"News/newssharedcontent-n";
        self.WebsiteStr = [NSString stringWithFormat:@"%@%ld%@%@%@%@", str1, indexPath.row - 1, str2, p, idStr, str3];
        NSLog(@"%@", self.WebsiteStr);
    } else if ([mediatypeStr isEqualToString:@"3"]) {
        NSString *p = @"news/videosharedcontent-n";
        self.WebsiteStr = [NSString stringWithFormat:@"%@%ld%@%@%@%@", str1, indexPath.row, str2, p, idStr, str3];
        NSLog(@"%@", self.WebsiteStr);
    }
    
    SHDetailViewController *detail = [[SHDetailViewController alloc] init];
    [self.navigationController pushViewController:detail animated:YES];
    detail.model = self.lastestArray[indexPath.row];
    detail.model.detailStr = self.WebsiteStr;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
